import "babel-polyfill";
import RBTree from "./rbtree";

export var OrderedSetTemplate = function(compare = (x, y) => x - y) {
    return class {
        constructor() {
            this.tree = new (RBTree(compare))(...arguments);
        }

        get [Symbol.toStringTag]() {
            return "OrderedSet";
        }

        get size() {
            return this.tree.size;
        }

        *[Symbol.iterator](direction = 1) {
            yield* this.tree[Symbol.iterator](direction);
        }

        has(value) {
            return this.tree.has(value);
        }
        add() {
            return this.tree.add(...arguments);
        }
        delete(value) {
            return this.tree.delete(value);
        }
    };
};

export default OrderedSetTemplate();
